<?php

if (!defined('SMF'))
	die('Hacking attempt...');

function snet_pre_load()
{
	// We need to know what version we're on.
	global $snet_version, $snet_version_shorts;
	$snet_version = 'SimpleNetwork Alpha Preview 2';
	$snet_version_short = 'AP2';
	
	// Load strings for the help popups.
	loadLanguage('SimpleNetwork-Help');
}

function snet_admin_menu($admin_menu)
{
	global $txt, $settings, $context;
	
	loadLanguage('SimpleNetwork-Admin');
	
	// Add the new admin areas.
	$admin_menu['simplenetwork'] = array(
		'title' => $txt['snet_admin_button'],
		'permission' => array('admin_forum'),
		'areas' => array(
			'snet-info' => array(
				'label' => $txt['snet_admin_button_info'],
				'file' => '/snet/SN-Admin.php',
				'icon' => '/snet/main.png',
				'function' => 'snet_admin_info',
				'subsections' => array(
				),
			),
			'snet-settings' => array(
				'label' => $txt['snet_admin_button_settings'],
				'file' => '/snet/SN-Admin.php',
				'icon' => '/snet/settings.png',
				'function' => 'snet_admin_settings',
				'subsections' => array(
					'general' => array($txt['snet_admin_button_settings_general']),
					'posting' => array($txt['snet_admin_button_settings_posting']),
					'social_options' => array($txt['snet_admin_button_settings_social_options']),
				),
			),			
		),
	);
	
	// JS and CSS, pretty, pretty!
	$context['html_headers'] .= '
	<link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/css/simplenetwork.css" /> 
	<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/snet/jquery.js"></script>
	<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/snet/simplenetwork.js"></script>
	<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/snet/jquery.li-scroller.js"></script>';
}

function snet_action_array($actions)
{
	// Add the Ajax action to the array so we can do stuff the cool way.
	$actions['snet-ajax'] = array('/snet/SN-Ajax.php', 'SN_Ajax');
}

function snet_delete_member($member)
{
	global $smcFunc;
	
	// Wheather they like it or not, an account deletion will permanently delete their status updates, likes, and comments. If they wanna come back later, then that's too bloody bad for them.
	$smcFunc['db_query']('', '
		DELETE FROM {db_prefix}snet_status_updates
		WHERE id_user = {int:member}',
		array(
			'member' => $member,
		)
	);	
	$smcFunc['db_query']('', '
		DELETE FROM {db_prefix}snet_likes
		WHERE id_liker = {int:member}',
		array(
			'member' => $member,
		)
	);
	$smcFunc['db_query']('', '
		DELETE FROM {db_prefix}snet_comments
		WHERE id_user = {int:member}',
		array(
			'member' => $member,
		)
	);		
	$smcFunc['db_query']('', '
		DELETE FROM {db_prefix}snet_users
		WHERE id_user = {int:member}',
		array(
			'member' => $member,
		)
	);		
}

function snet_note_new_topic($msgOptions, $topicOptions, $posterOptions)
{
	global $sourcedir;
	
	require_once($sourcedir . '/snet/Subs-SimpleNetwork-Post.php');
	
	snet_post_status_update(array(
		'body' => @serialize(array('body' => 'snet_note_new_topic_body', 'status_expl' => 'snet_note_new_topic', 'note_type' => 'new_topic','replacements' => array('{topic}' => $topicOptions['id'], '{subject}' => 'snet_fetch_topic_subject(' . $topicOptions['id'] . ');', '{body}' => 'snet_fetch_message_body(' . $msgOptions['id'] . ');', '{icon}' => 'snet_fetch_message_icon(' . $msgOptions['id'] . ');'), 'evalrepl' => array('{subject}','{body}','{icon}'), 'extra_link' => array('snet_note_extra_read_topic',array($topicOptions['id'])))),
		'type' => 7,
	),$posterOptions['id']);
}

// Copyright, just because.
function snet_copyright($buffer)
{
	global $snet_version;

	// Oi, SN's running. All hands on bloody deck and show that darn copyright!!
	if(strpos($buffer, '<span style="display: none;" id="snet" />') !== false)
		$buffer = preg_replace('~(, Simple Machines LLC</a>)~', ', Simple Machines LLC</a><br /><span class="smalltext">Powered by <a href="http://www.marcusforsberg.net/">' .$snet_version .'</a> &copy; 2011 <a href="http://www.marcusforsberg.net/">Marcus Forsberg</a></span>', $buffer);

	return $buffer;	
}

?>